

import java.util.Random;


public class TestRBtree {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		RBTree tree = new RBTree();
		
		/*
		System.out.println(tree.empty());
		System.out.println(tree.insert(5));
		System.out.println(tree.insert(3));
		System.out.println(tree.insert(1));
		System.out.println(tree.insert(2));
		System.out.println(tree.insert(6));
		System.out.println(tree.insert(35));
		System.out.println(tree.insert(22));
		System.out.println(tree.insert(9));
		System.out.println(tree.insert(16));
		System.out.println(tree.insert(4));
		System.out.println(tree.delete(35));
		System.out.println(tree.delete(6));
		System.out.println(tree.size());
		tree.printTree();
		System.out.println(tree.max());
		System.out.println(tree.min());
		System.out.println(Arrays.toString(tree.toIntArray()));
		*/
		Random rangen = new Random();

		System.out.println("Serial Nr, Average, Maximum");
		for (int i=0;i<10;i++)
		{
			tree = new RBTree();
			int colorChanges = 0;
			int maxColorChanges = 0;
			int tmpColorChanges = 0;
			int maxAvgColorChanges = 0;
			int tmpAvgColorChanges = 0;
			int insertWithMaxAvg = 0;
			while (tree.size() < 50000) 
			{
				int r = rangen.nextInt()+1;
				tmpColorChanges = tree.insert(r);
				if (tmpColorChanges > maxColorChanges)
				{
					maxColorChanges = tmpColorChanges;
				}
				colorChanges += tmpColorChanges;
				
				tmpAvgColorChanges = (float)colorChanges/tree.size;
				if(tmpAvgColorChanges>maxAvgColorChanges){
					maxAvgColorChanges =tmpAvgColorChanges;
					insertWithMaxAvg = tree.size;
				}
			}
			System.out.println(i+1 + "," + (float)colorChanges/50000 + "," maxAvgColorChanges+","+insertWithMaxAvg+","+ maxColorChanges);
		}
		
		
		
		
		// System.out.print(Arrays.toString(tree.toIntArray()));

	}

}
